package com.haina.shop.result;

import lombok.Data;

import java.io.Serializable;

@Data
public class ServiceResult<T> implements Serializable {
    private String code="00000";
    private String msg="ok";
    private T data;
    private String version="mall4j.v230424";
    private Integer timestamp=null;
    private String sign=null;
    private boolean success=true;
    private boolean fail=false;

    /**
     * 登入成功带token
     * @param data
     * @return
     * @param <T>
     */

    public  static <T> ServiceResult<T> LoginSuccess(T data) {
        ServiceResult<T> result=new ServiceResult<T>();
        result.setData(data);
        return result;
    }


    //带数据的成功响应的方法
    public static <T> ServiceResult<T> success(T data) {
        ServiceResult<T> result = new ServiceResult<>();
        result.setData(data);
        return result;
    }
    //不带数据的成功响应的方法
    public static ServiceResult success() {
        ServiceResult result = new ServiceResult();
        return result;
    }
    //不带数据的失败响应的方法
    public static ServiceResult error() {
        ServiceResult result = new ServiceResult();
        result.setFail(true);
        result.setSuccess(false);
        result.setMsg("信息错误");
        return result;
    }
    public static ServiceResult error(String code,String msg) {
        ServiceResult result = new ServiceResult();
        result.setFail(true);
        result.setSuccess(false);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


}
